package org.iubbo.proxy.controller;

import org.iubbo.proxy.model.dto.*;
import org.iubbo.proxy.service.RegisterConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static org.iubbo.proxy.config.CommonConstants.SAMPLE_REQ;

/**
 * 测试平台的invoke控制器
 *
 * @author idea
 * @date 2019/12/19
 * @version V1.0
 */
@RestController
@RequestMapping("/dubbo-register")
public class DubboRegisterController {

    @Autowired
    private RegisterConfigService registerConfigService;


    @PostMapping("/addOne")
    @ResponseBody
    public Object addOne(@RequestBody(required = false) DubboRegisterConfigDTO param) {
        if (param == null) {
            return SAMPLE_REQ;
        }

        return registerConfigService.addOne(param);
    }

    @GetMapping(value = "/getAllRegisterConfig")
    public ResponseDTO<List<DubboRegisterConfigDTO>> getAllRegisterConfig(int type) {
        List<DubboRegisterConfigDTO> dubboRegisterConfigDTOList = registerConfigService.getRegisterConfig(type);
        return ResponseUtil.successResponse(dubboRegisterConfigDTOList);
    }

}
